package com.webapp.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.webapp.domain.entity.Counselor;
@Repository("counselorDAO")
public class CounselorDAO extends AbstractDAO<Counselor> {
	
	public void inserCounselor(Counselor counselor){
		save(counselor);
	}
	
	public Counselor selectCounselor(Map<String, Object> map){
		List<Object> list = new ArrayList<Object>();
		String sql = "where 1=1 ";
		for(String key : map.keySet()){
			if ("name".equals(key)) {
				sql +="and ("+key+"=? or counselor.counselorDetail.phone=?) ";
				list.add(map.get(key));
				list.add(map.get(key));
			}else{
				sql += "and "+key+"=? ";
				list.add(map.get(key));
			}
		}
		return get(sql, list.toArray());
	}
	
	public void updateCounselor(Counselor counselor){
		/*Session session = getSession();
		session.beginTransaction();*/
		getSession().merge(counselor);
		/*session.getTransaction().commit();
		session.close();*/
	}
}
